function draw() {
    $("input[name=csvfile]").csv_arr(function(arr){
        // console.log(arr);
        var tblStr = "<table border='1'>";
        $.each(arr,function(i,line){
            tblStr += "<tr>";
            $.each(line,function(i,cell){
                tblStr += "<td>"+cell+"</td>";
            });
            tblStr += "</tr>"
        });
        $("#resTable").html(tblStr);
        // 取每个用户名组成新数组
        function trans(arr) {
            let result = []
                arr.forEach(item =>{
                    item.forEach((d,i)=>{
                        let a = result[i] = result[i] || []
                        a.push(d)
                    })
                })
            var newArr = [...new Set(result[0])]
            // 创建set集合并删除表头元素
            var user_filter = new Set(newArr)
            user_filter.delete("用户名") // 在引号中修改表头内容
            console.log(user_filter);
            setTimeout(() => {
                console.log("全部用户载入完毕");
                console.log("总共"+user_filter.size+"名满足条件用户");
                console.log("开始抽奖，倒计时5秒");
                var sec = 5;
                function countdown() {
                    if (sec == 0) {
                        clearInterval(timer1)
                        return
                    } else {
                        console.log(sec);
                        sec--;
                    }
                }
                var timer1 = setInterval(countdown,1000)
                setTimeout(() => {
                    var user = 1;
                    function drawStart() {
                        if (user > 13) {
                            console.log("");
                            console.log("恭喜以上中奖同学！！！");
                            clearInterval(timer2)
                            return
                        }else if (user > 3) {
                            console.log("");
                            console.log("开始抽取三等奖（"+(user-3)+"/10名）");
                            // 生成随机数，打印中奖者信息
                            var lucky_num = parseInt(Math.random()*(user_filter.size),10)
                            var user_name = Array.from(user_filter)[lucky_num]
                            console.log("第"+user+"位中奖用户【三等奖】："+user_name);
                            // 不放回抽样
                            user_filter.delete(user_name)
                            user++
                        }else if (user > 1) {
                            console.log("");
                            console.log("开始抽取二等奖（"+(user-1)+"/2名）");
                            var lucky_num = parseInt(Math.random()*(user_filter.size),10)
                            var user_name = Array.from(user_filter)[lucky_num]
                            console.log("第"+user+"位中奖用户【二等奖】："+user_name);
                            user_filter.delete(user_name)
                            user++
                        }else{
                            console.log("");
                            console.log("开始抽取一等奖（1/1名）");
                            var lucky_num = parseInt(Math.random()*(user_filter.size),10)
                            var user_name = Array.from(user_filter)[lucky_num]
                            console.log("第"+user+"位中奖用户【一等奖】："+user_name);
                            user_filter.delete(user_name)
                            user++
                        }
                    }
                    var timer2 = setInterval(drawStart,1500);
                }, 5200);
                return
            },3500);
        }
        trans(arr)
    });
}